package com.vito.oa.act.extend.action;

import java.text.MessageFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.model.FtpModel;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.base.util.Contants;
import com.vito.base.util.Validata;
import com.vito.oa.act.extend.service.OaActProgressTableService;
@Controller
@RequestMapping("oa/act/actProgressTable")
public class OaActProgressTableAction extends BaseAction{
	private static Logger log = LoggerFactory.getLogger(OaActProgressTableAction.class);
	
	@Reference
	private OaActProgressTableService actProgressTableService;
	
	@RequestMapping("queryBussInfo")
	@ResponseBody
	public Result queryBussInfo(String processKey,String processNodeId,String bussId, String taskId){
		Result res = new Result();
		try {
			if(Validata.isNullOrEmpty(processKey)){
				res.setCode(Result.CODE_PARA_ERROR);
				res.setMsg(MessageFormat.format(ResMsg.MSG_DATA_NEED,"流程编码"));
				return res;
			}else if(Validata.isNullOrEmpty(processNodeId)){
				res.setCode(Result.CODE_PARA_ERROR);
				res.setMsg(MessageFormat.format(ResMsg.MSG_DATA_NEED,"流程节点编码"));
				return res;
			}else if(Validata.isNullOrEmpty(bussId)){
				res.setCode(Result.CODE_PARA_ERROR);
				res.setMsg(MessageFormat.format(ResMsg.MSG_DATA_NEED,"业务编码"));
				return res;
			}else if(Validata.isNullOrEmpty(taskId)){
				res.setCode(Result.CODE_PARA_ERROR);
				res.setMsg(MessageFormat.format(ResMsg.MSG_DATA_NEED,"任务编码"));
				return res;
			}
			
			res.setData(actProgressTableService.queryBussInfo(processKey, processNodeId, bussId,taskId));
			res.setCode(Result.CODE_OK);
		} catch (Exception e) {
			log.error("查询异常：",e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	@RequestMapping("queryBussNeedCols")
	@ResponseBody
	public Result queryBussNeedCols(String processKey,String processNodeId){
		Result res = new Result();
		try {
			if(Validata.isNullOrEmpty(processKey)){
				res.setCode(Result.CODE_PARA_ERROR);
				res.setMsg(MessageFormat.format(ResMsg.MSG_DATA_NEED,"流程编码"));
				return res;
			}
			if(Validata.isNullOrEmpty(processNodeId)){
				processNodeId = Contants.FORM_PROCESS_START;
			}
			res.setData(actProgressTableService.queryBussNeedCols(processKey, processNodeId));
			res.setCode(Result.CODE_OK);
		} catch (Exception e) {
			log.error("查询异常：",e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	@RequestMapping("queryOverBussInfo")
	@ResponseBody
	public Result queryOverBussInfo(String path){
		Result res = new Result();
		try {
			if(Validata.isNullOrEmpty(path)){
				res.setCode(Result.CODE_PARA_ERROR);
				res.setMsg(MessageFormat.format(ResMsg.MSG_DATA_NEED,"流程参数"));
				return res;
			}
			res.setData(actProgressTableService.queryOverInfoSingle(path));
			res.setCode(Result.CODE_OK);
		} catch (Exception e) {
			log.error("查询异常：",e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
}
